package xc.com.course.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xc.com.common.Result;
import xc.com.course.domain.Teachplan;
import xc.com.course.service.TeachplanService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuolizhong
 * @since 2021-06-03
 */
@RestController
@RequestMapping("/teachplan")
@Api(tags = "teachplan接口",description = "课程计划信息的增删改查")
@CrossOrigin
public class TeachplanController {
     @Autowired
    private TeachplanService teachplanService;

    /**
     * 添加课程计划信息
     * @param id
     * @param teachplan
     * @return
     */
     @PostMapping("/add/{id}")
     @ApiOperation("添加课程计划信息")
     public Result addTeachPlan(@PathVariable("id")String id ,@RequestBody Teachplan teachplan){
         teachplan.setCourseid(id);
         teachplan.setGrade("3");
         teachplan.setStatus("0");
         Result result = teachplanService.addTeachplan(teachplan);
         return result;
     }

    /**
     * 根据Id查询课程计划信息
     * @param id
     * @return
     */
     @GetMapping("/findId/{id}")
     @ApiOperation("根据Id查询课程计划信息")
    public Teachplan[] findById(@PathVariable("id")String id){
         Teachplan[] teachplans = teachplanService.findByCourseId(id);
         return teachplans;
     }
    @GetMapping("/findByCourseId/{id}")
    @ApiOperation("根据Id查询课程计划信息")
    public Teachplan[] findByCourseId(@PathVariable("id")String courseId){
        Teachplan allTeachPlan = teachplanService.findAllTeachPlan(courseId);
        Teachplan[] teachplans=new Teachplan[]{allTeachPlan};
        return teachplans;
    }

}

